home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
016a
/
gofer221.zip
/
PARSER.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-11-20
|
39KB
|
1,266 lines
/* A YACC parser generated from "parser.y" */
# line 12
#ifndef lint
#define lint
#endif
#define typeDefn(line,lhs,rhs) newTypeDefn(intOf(line),lhs,rhs,FALSE)
#define dataDefn(line,lhs,rhs) newTypeDefn(intOf(line),lhs,rhs,TRUE)
#define sigdecl(l,vs,t) ap(SIGDECL,triple(l,vs,t))
#define grded(gs) ap(GUARDED,gs)
#define letrec(bs,e) (nonNull(bs) ? ap(LETREC,pair(bs,e)) : e)
#define yyerror(s) /* errors handled elsewhere */
#define YYSTYPE Cell
static Cell local gcShadow Args((Int,Cell));
static Void local syntaxError Args((String));
static String local unexpected Args((Void));
static Cell local checkPrec Args((Cell));
static Void local fixDefn Args((Syntax,Cell,Cell,List));
static Void local setSyntax Args((Int,Syntax,Cell));
static Cell local buildTuple Args((List));
static Cell local checkClass Args((Cell));
static List local checkContext Args((List));
static Cell local tidyInfix Args((Cell));
/* For the purposes of reasonably portable garbage collection, it is
* necessary to simulate the YACC stack on the Gofer stack to keep
* track of all intermediate constructs. The lexical analyser
* pushes a token onto the stack for each token that is found, with
* these elements being removed as reduce actions are performed,
* taking account of look-ahead tokens as described by gcShadow()
* below.
*
* Of the non-terminals used below, only start and topdecl do not leave
* any values of the Gofer stack. The same is true for the terminals
* EVALEX and MODULE. At the end of a successful parse, there should only
* be one element left on the stack, containing the result of the parse.
*/
#define gc0(e) gcShadow(0,e)
#define gc1(e) gcShadow(1,e)
#define gc2(e) gcShadow(2,e)
#define gc3(e) gcShadow(3,e)
#define gc4(e) gcShadow(4,e)
#define gc5(e) gcShadow(5,e)
#define gc6(e) gcShadow(6,e)
#define EVALEX 257
#define MODULE 258
#define SCRIPT 259
#define COCO 260
#define INFIXL 261
#define INFIXR 262
#define INFIX 263
#define FUNARROW 264
#define UPTO 265
#define CASEXP 266
#define OF 267
#define IF 268
#define THEN 269
#define ELSE 270
#define WHERE 271
#define TYPE 272
#define DATA 273
#define FROM 274
#define LET 275
#define IN 276
#define VAROP 277
#define VARID 278
#define NUMLIT 279
#define CHARLIT 280
#define STRINGLIT 281
#define REPEAT 282
#define CONOP 283
#define CONID 284
#define TCLASS 285
#define IMPLIES 286
#define TINSTANCE 287
#define PRIMITIVE 288
#define yyclearin yychar = -1
#define yyerrok yyerrflag = 0
extern int yychar;
extern short yyerrflag;
#ifndef YYMAXDEPTH
#define YYMAXDEPTH 150
#endif
#ifndef YYSTYPE
#define YYSTYPE int
#endif
YYSTYPE yylval, yyval;
# define YYERRCODE 256
#line 346
static Cell local gcShadow(n,e) /* keep parsed fragments on stack */
Int n;
Cell e; {
/* If a look ahead token is held then the required stack transformation
* is:
* pushed: n 1 0 1 0
* x1 | ... | xn | la ===> e | la
* top() top()
*
* Othwerwise, the transformation is:
* pushed: n-1 0 0
* x1 | ... | xn ===> e
* top() top()
*/
if (yychar>=0) {
pushed(n-1) = top();
pushed(n) = e;
}
else
pushed(n-1) = e;
sp -= (n-1);
return e;
}
static Void local syntaxError(s) /* report on syntax error */
String s; {
ERROR(row) "Syntax error in %s (unexpected %s)", s, unexpected()
EEND;
}
static String local unexpected() { /* find name for unexpected token */
static char buffer[100];
switch (yychar) {
case 0 : return "end of input";
#define keyword(kw) sprintf(buffer,"\"%s\" keyword",kw); return buffer;
case INFIXL : keyword("infixl");
case INFIXR : keyword("infixr");
case INFIX : keyword("infix");
case TINSTANCE : keyword("instance");
case TCLASS : keyword("class");
case PRIMITIVE : keyword("primitive");
case CASEXP : keyword("case");
case OF : keyword("of");
case IF : keyword("if");
case THEN : keyword("then");
case ELSE : keyword("else");
case WHERE : keyword("where");
case TYPE : keyword("type");
case DATA : keyword("data");
case LET : keyword("let");
case IN : keyword("in");
#undef keyword
case FUNARROW : return "`->'";
case '=' : return "`='";
case COCO : return "`::'";
case '-' : return "`-'";
case ',' : return "comma";
case '@' : return "`@'";
case '(' : return "`('";
case ')' : return "`)'";
case '|' : return "`|'";
case ';' : return "`;'";
case UPTO : return "`..'";
case '[' : return "`['";
case ']' : return "`]'";
case FROM : return "`<-'";
case '\\' : return "`\\'";
case '~' : return "`~'";
case '`' : return "``'";
case VAROP :
case VARID :
case CONOP :
case CONID : sprintf(buffer,"symbol \"%s\"",
textToStr(textOf(yylval)));
return buffer;
case NUMLIT : return "numeric literal";
case CHARLIT : return "character literal";
case STRINGLIT : return "string literal";
case IMPLIES : return "`=>";
default : return "token";
}
}
static Cell local checkPrec(p) /* Check for valid precedence value */
Cell p; {
if (!isInt(p) || intOf(p)<MIN_PREC || intOf(p)>MAX_PREC) {
ERROR(row) "Precedence value must be an integer in the range [%d..%d]",
MIN_PREC, MAX_PREC
EEND;
}
return p;
}
static Void local fixDefn(a,line,p,ops)/* Declare syntax of operators */
Syntax a;
Cell line;
Cell p;
List ops; {
Int l = intOf(line);
a = mkSyntax(a,intOf(p));
map2Proc(setSyntax,l,a,ops);
}
static Void local setSyntax(line,sy,op)/* set syntax of individ. operator */
Int line;
Syntax sy;
Cell op; {
addSyntax(line,textOf(op),sy);
opDefns = cons(op,opDefns);
}
static Cell local buildTuple(tup) /* build tuple (x1,...,xn) from list*/
List tup; { /* [xn,...,x1] */
Int n = 0;
Cell t = tup;
Cell x;
do { /* . . */
x = fst(t); /* / \ / \ */
fst(t) = snd(t); /* xn . . xn */
snd(t) = x; /* . ===> . */
x = t; /* . . */
t = fun(x); /* . . */
n++; /* / \ / \ */
} while (nonNull(t)); /* x1 NIL (n) x1 */
fst(x) = mkTuple(n);
return tup;
}
/* The yacc parser presented above is not sufficiently powerful to
* determine whether a tuple at the front of a sigType is part of a
* context: e.g. (Eq a, Num a) => a -> a -> a
* or a type: e.g. (Tree a, Tree a) -> Tree a
*
* Rather than complicate the grammar, both are parsed as tuples of types,
* using the following checks afterwards to ensure that the correct syntax
* is used in the case of a tupled context.
*/
static List local checkContext(con) /* validate type class context */
Type con; {
if (con==UNIT) /* allows empty context () */
return NIL;
else if (whatIs(getHead(con))==TUPLE) {
List qs = NIL;
while (isAp(con)) { /* undo work of buildTuple :-( */
Cell temp = fun(con);
fun(con) = arg(con);
arg(con) = qs;
qs = con;
con = temp;
checkClass(hd(qs));
}
return qs;
}
else /* single context expression */
return singleton(checkClass(con));
}
static Cell local checkClass(c) /* check that type expr is a class */
Cell c; { /* constrnt of the form C t1 .. tn */
Cell cn = getHead(c);
if (!isCon(cn))
syntaxError("class expression");
else if (argCount<1) {
ERROR(row) "Class \"%s\" must have at least one argument",
textToStr(textOf(cn))
EEND;
}
return c;
}
/* expressions involving a sequence of two or more infix operator symbols
* are parsed as elements of type:
* InfixExpr ::= [Expr]
* | ap(ap(Operator,InfixExpr),Expr)
*
* thus x0 +1 x1 ... +n xn is parsed as: +n (....(+1 [x0] x1)....) xn
*
* Once the expression has been completely parsed, this parsed form is
* `tidied' according to the precedences and associativities declared for
* each operator symbol.
*
* The tidy process uses a `stack' of type:
* TidyStack ::= ap(ap(Operator,TidyStack),Expr)
* | NIL
* when the ith layer of an InfixExpr has been transferred to the stack, the
* stack is of the form: +i (....(+n NIL xn)....) xi
*
* The tidy function is based on a simple shift-reduce parser:
*
* tidy :: InfixExpr -> TidyStack -> Expr
* tidy [m] ss = foldl (\x f-> f x) m ss
* tidy (m*n) [] = tidy m [(*n)]
* tidy (m*n) ((+o):ss)
* | amb = error "Ambiguous"
* | shift = tidy m ((*n):(+o):ss)
* | reduce = tidy (m*(n+o)) ss
* where sye = syntaxOf (*)
* (ae,pe) = sye
* sys = syntaxOf (+)
* (as,ps) = sys
* amb = pe==ps && (ae/=as || ae==NON_ASS)
* shift = pe>ps || (ps==pe && ae==LEFT_ASS)
* reduce = otherwise
*
* N.B. the conditions amb, shift, reduce are NOT mutually exclusive and
* must be tested in that order.
*
* As a concession to efficiency, we lower the number of calls to syntaxOf
* by keeping track of the values of sye, sys throughout the process. The
* value APPLIC is used to indicate that the syntax value is unknown.
*/
static Cell local tidyInfix(e) /* convert InfixExpr to Expr */
Cell e; { /* :: InfixExpr */
Cell s = NIL; /* :: TidyStack */
Syntax sye = APPLIC; /* Syntax of op in e (init unknown) */
Syntax sys = APPLIC; /* Syntax of op in s (init unknown) */
Cell temp;
while (nonNull(tl(e))) {
if (isNull(s)) {
s = e;
e = arg(fun(s));
arg(fun(s)) = NIL;
sys = sye;
sye = APPLIC;
}
else {
if (sye==APPLIC) { /* calculate sye (if unknown) */
sye = syntaxOf(textOf(fun(fun(e))));
if (sye==APPLIC) sye=DEF_OPSYNTAX;
}
if (sys==APPLIC) { /* calculate sys (if unknown) */
sys = syntaxOf(textOf(fun(fun(s))));
if (sys==APPLIC) sys=DEF_OPSYNTAX;
}
if (precOf(sye)==precOf(sys) && /* amb */
(assocOf(sye)!=assocOf(sys) || assocOf(sye)==NON_ASS)) {
ERROR(row) "Ambiguous use of operator \"%s\" with \"%s\"",
textToStr(textOf(fun(fun(e)))),
textToStr(textOf(fun(fun(s))))
EEND;
}
else if (precOf(sye)>precOf(sys) || /* shift */
(precOf(sye)==precOf(sys) && assocOf(sye)==LEFT_ASS)) {
temp = arg(fun(e));
arg(fun(e)) = s;
s = e;
e = temp;
sys = sye;
sye = APPLIC;
}
else { /* reduce */
temp = arg(fun(s));
arg(fun(s)) = arg(e);
arg(e) = s;
s = temp;
sys = APPLIC;
/* sye unchanged */
}
}
}
e = hd(e);
while (nonNull(s)) {
temp = arg(fun(s));
arg(fun(s)) = e;
e = s;
s = temp;
}
return e;
}
/*-------------------------------------------------------------------------*/
short yyexca[] ={
-1, 1,
0, -1,
-2, 0,
-1, 77,
260, 84,
44, 84,
-2, 109,
-1, 87,
286, 22,
-2, 21,
-1, 135,
264, 26,
286, 26,
-2, 60,
-1, 224,
264, 26,
283, 26,
-2, 18,
-1, 225,
264, 29,
283, 29,
-2, 19,
};
#define YYNPROD 154
# define YYLAST 651
short yyact[]={
21, 191, 152, 122, 97, 14, 231, 253, 94, 157,
98, 186, 125, 132, 203, 132, 32, 219, 204, 21,
193, 190, 83, 84, 14, 245, 179, 216, 276, 153,
42, 121, 38, 21, 256, 85, 82, 187, 14, 244,
129, 94, 4, 2, 3, 180, 144, 245, 252, 232,
140, 26, 21, 166, 229, 19, 151, 14, 78, 95,
21, 54, 35, 30, 64, 51, 177, 65, 139, 142,
26, 199, 21, 185, 19, 86, 31, 14, 163, 222,
162, 44, 214, 111, 26, 118, 18, 112, 19, 21,
75, 139, 95, 133, 14, 49, 235, 206, 212, 233,
120, 213, 15, 26, 118, 18, 124, 19, 21, 101,
81, 26, 6, 226, 217, 19, 44, 47, 107, 18,
94, 172, 210, 26, 5, 211, 148, 19, 21, 170,
36, 37, 145, 14, 145, 94, 242, 271, 18, 102,
26, 6, 239, 55, 19, 116, 18, 101, 61, 134,
134, 21, 241, 175, 47, 168, 171, 106, 18, 26,
107, 167, 103, 19, 21, 243, 56, 113, 137, 123,
117, 95, 182, 183, 194, 18, 41, 126, 127, 26,
6, 174, 40, 19, 104, 202, 95, 105, 115, 146,
198, 240, 118, 62, 18, 60, 13, 205, 59, 33,
20, 147, 26, 118, 58, 150, 19, 27, 118, 143,
141, 118, 255, 192, 18, 26, 119, 189, 196, 19,
128, 69, 70, 71, 89, 159, 228, 164, 88, 165,
218, 130, 67, 68, 169, 119, 173, 18, 29, 22,
23, 24, 25, 178, 28, 73, 93, 74, 72, 66,
18, 29, 92, 29, 69, 70, 71, 29, 22, 23,
24, 25, 43, 28, 197, 67, 68, 200, 45, 188,
149, 29, 22, 23, 24, 25, 11, 28, 73, 93,
74, 72, 265, 178, 272, 155, 9, 176, 8, 184,
29, 22, 23, 24, 25, 7, 28, 52, 29, 22,
23, 24, 25, 53, 28, 11, 277, 138, 114, 273,
29, 22, 23, 24, 25, 9, 28, 8, 264, 176,
257, 234, 87, 119, 7, 236, 237, 29, 22, 23,
24, 25, 268, 28, 119, 201, 89, 263, 248, 119,
250, 251, 119, 259, 11, 221, 29, 22, 23, 24,
25, 89, 28, 63, 9, 261, 260, 262, 93, 90,
1, 91, 257, 7, 92, 266, 29, 22, 23, 24,
25, 181, 28, 93, 249, 79, 10, 0, 17, 225,
0, 0, 275, 0, 39, 46, 0, 0, 0, 29,
22, 23, 24, 25, 238, 28, 136, 136, 279, 12,
0, 0, 29, 22, 23, 24, 25, 76, 28, 77,
176, 0, 76, 0, 77, 0, 0, 158, 160, 16,
0, 57, 0, 0, 0, 0, 34, 0, 0, 108,
0, 0, 0, 135, 135, 48, 0, 0, 50, 96,
0, 0, 176, 0, 270, 0, 99, 0, 274, 0,
0, 131, 154, 80, 156, 76, 0, 77, 0, 0,
0, 0, 0, 0, 0, 0, 0, 48, 161, 100,
0, 0, 0, 0, 0, 208, 209, 0, 109, 110,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 76, 0, 77, 0, 154, 0, 0,
220, 0, 223, 0, 0, 0, 0, 227, 96, 0,
0, 0, 0, 0, 0, 0, 0, 0, 195, 0,
0, 0, 0, 0, 0, 76, 0, 77, 207, 0,
0, 0, 0, 0, 246, 0, 247, 0, 0, 224,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 230, 0, 0, 0, 0, 0, 0, 0, 0,
0, 215, 0, 0, 131, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 223, 269, 0, 0, 0,
0, 0, 0, 0, 0, 0, 154, 156, 0, 0,
0, 0, 154, 156, 0, 278, 0, 0, 254, 0,
0, 0, 0, 0, 0, 0, 258, 0, 77, 76,
0, 77, 224, 0, 0, 0, 207, 0, 0, 0,
0, 0, 267, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 258, 0,
77 };
short yypact[]={
-214,-1000, 49, -60,-1000,-255, 124, -61, 49, 49,
-228,-1000, -15, -15, 124, 124,-1000, 31, 124,-1000,
-1000, 20,-1000,-1000,-1000,-1000, 49,-1000,-1000,-1000,
-7,-1000, -65, 111,-1000, 32,-247,-244, 80, 32,
-1000,-1000,-1000,-1000,-274,-1000, 32, 124,-1000, 124,
-1000, 68, 98, 121,-1000, 143, 116, -15, 124, 124,
-10, 43, 74, 86,-1000,-1000,-1000,-253,-253,-267,
-267,-267, -25, 80, 80, 47, 8, 31, 32, 49,
-1000, 67,-1000, 49, -67,-1000,-284,-1000,-235,-1000,
1,-1000, 1,-1000, -32, 80, -15, -16, -18,-1000,
-1000,-1000,-1000,-1000,-1000, 49,-1000, 49, 12, 120,
114,-1000, 49, 49, 49,-1000, -40,-1000,-1000,-1000,
5,-1000,-1000, -35, -15,-1000, -15, -15, 29,-1000,
-1000,-270, -8,-250,-285, 1,-1000,-251, 80, -27,
-1000,-255, 49, 10,-1000, 49, 67,-1000, -21,-262,
-252, 32, 80, 80,-1000,-1000,-1000,-1000, 81, 57,
-11, 32,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-238,
70,-1000, -44,-1000,-1000,-1000,-1000, 80,-1000, 95,
69,-1000, 69, 69, 80, -27,-1000, 106, 98,-1000,
-69,-278,-1000, -74,-1000,-1000,-1000, 55,-1000, 49,
35,-1000,-1000, 49, 49, 83,-1000, -99,-1000,-1000,
-1000, 80,-1000, 80,-1000,-1000, 49, 49, 49, 49,
-1000, -76,-1000,-276, 1, 1, -15,-1000,-1000, 32,
1, 1, 32, 88, 55, 49,-1000,-1000,-1000, -21,
-1000,-255, -77, 49,-1000, 32,-1000,-1000,-1000,-1000,
-1000,-1000, 95, 80,-1000, 78,-1000, 24, 8, 67,
49,-1000,-1000,-1000,-1000,-1000,-1000,-236,-1000,-1000,
-1000, -21, 80,-1000,-1000,-247, 49,-1000,-1000,-1000 };
short yypgo[]={
0, 360, 121, 76, 353, 188, 64, 36, 100, 322,
345, 79, 359, 35, 75, 228, 361, 225, 106, 45,
371, 182, 176, 220, 40, 378, 93, 217, 213, 212,
110, 34, 90, 376, 50, 210, 209, 46, 207, 200,
199, 197, 419, 399, 196, 102, 166, 195, 97, 191,
152, 136, 39, 129, 156, 170 };
short yyr1[]={
0, 1, 1, 1, 1, 4, 4, 4, 4, 4,
6, 6, 8, 8, 8, 10, 10, 11, 11, 11,
13, 13, 14, 9, 9, 9, 15, 15, 16, 16,
16, 16, 16, 16, 12, 12, 17, 17, 6, 6,
6, 18, 18, 19, 19, 20, 20, 20, 21, 21,
22, 22, 6, 23, 23, 23, 24, 6, 6, 26,
26, 27, 27, 28, 28, 29, 29, 31, 31, 7,
7, 30, 30, 34, 34, 35, 35, 3, 36, 36,
37, 37, 37, 32, 32, 25, 25, 38, 38, 39,
39, 2, 2, 2, 2, 2, 2, 2, 40, 40,
33, 33, 33, 44, 44, 43, 43, 45, 45, 42,
42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
42, 42, 42, 42, 42, 46, 46, 41, 41, 48,
49, 49, 50, 50, 51, 51, 52, 47, 47, 47,
47, 47, 47, 47, 47, 53, 53, 54, 54, 54,
5, 5, 55, 55 };
short yyr2[]={
0, 2, 3, 4, 1, 3, 3, 1, 1, 1,
4, 4, 2, 1, 1, 3, 1, 3, 1, 1,
3, 1, 1, 1, 3, 1, 1, 1, 1, 1,
2, 3, 3, 3, 2, 2, 3, 3, 3, 3,
3, 1, 0, 3, 1, 1, 1, 1, 1, 3,
1, 3, 4, 3, 1, 1, 2, 3, 3, 3,
1, 4, 0, 4, 0, 3, 1, 3, 2, 3,
2, 3, 1, 2, 1, 2, 1, 4, 2, 1,
4, 5, 4, 3, 1, 1, 3, 1, 3, 1,
3, 4, 6, 6, 6, 3, 1, 1, 2, 1,
1, 3, 1, 3, 5, 2, 1, 2, 1, 1,
3, 2, 1, 1, 2, 1, 1, 1, 1, 3,
3, 3, 4, 4, 4, 3, 3, 3, 1, 2,
2, 1, 1, 2, 2, 1, 4, 0, 1, 1,
3, 3, 4, 2, 5, 3, 1, 3, 3, 1,
2, 1, 1, 1 };
short yychk[]={
-1000, -1, 257, 258, 256, -2, 92, 275, 268, 266,
-33, 256, -43, -44, 45, -45, -42, -25, 126, 95,
-39, 40, 279, 280, 281, 282, 91, -38, 284, 278,
123, -3, 271, -40, -42, 123, -2, -2, 260, -20,
-21, -22, 45, 277, 96, 283, -20, -45, -42, 64,
-42, 45, 277, 283, 41, -2, -46, -43, -21, -22,
-47, -2, -46, -4, -6, -7, 256, 272, 273, 261,
262, 263, 288, 285, 287, -32, -33, -25, 123, 264,
-42, -30, -7, 269, 267, -13, -14, -9, -15, 256,
-12, -16, 284, 278, 40, 91, -43, 278, 284, -43,
-42, 41, 41, 41, 41, 44, 41, 44, -20, -42,
-42, 93, 44, 124, 265, -5, 59, -55, 125, 256,
-8, 284, 256, -8, -18, 279, -18, -18, -23, -24,
256, -25, 40, -26, -14, -12, -9, -26, 260, 44,
-34, -35, 61, -36, -37, 124, -30, -2, 59, -5,
-2, 123, 286, 264, -16, 284, -16, 41, -9, -17,
-9, -20, 96, 96, -2, -2, 41, 41, 41, -2,
-53, -54, -2, -2, -6, -7, -55, 61, 278, 61,
-19, -20, -19, -19, 260, 44, 281, 45, 277, -27,
271, 286, -28, 271, -13, -25, -3, -2, -37, 61,
-2, -5, -7, 276, 270, -41, -48, -33, -9, -9,
41, 44, 41, 44, 93, -43, 265, 44, 274, 61,
-9, -10, -11, -9, -12, 284, 44, -9, -24, 123,
-12, 284, 123, 44, -2, 61, -2, -2, -5, 59,
-49, -50, -51, 264, -52, 124, -9, -9, -2, -54,
-2, -2, 124, 283, -20, -29, -31, -32, -33, -30,
268, -2, -2, -48, -3, -52, -2, -33, -11, -9,
-5, 59, 260, -34, -5, -2, 264, -31, -9, -2 };
short yydef[]={
0, -2, 0, 0, 4, 1, 0, 0, 0, 0,
96, 97, 100, 102, 0, 106, 108, 109, 0, 112,
113, 0, 115, 116, 117, 118, 137, 85, 89, 87,
0, 2, 0, 0, 99, 0, 0, 0, 0, 0,
45, 46, 47, 48, 0, 50, 0, 105, 107, 0,
111, 0, 48, 50, 114, 0, 0, 100, 0, 0,
0, 138, 139, 0, 7, 8, 9, 0, 0, 42,
42, 42, 0, 0, 0, 0, 0, -2, 0, 0,
98, 0, 72, 0, 0, 95, 0, -2, 23, 25,
26, 27, 29, 28, 0, 0, 101, 0, 0, 103,
110, 86, 88, 90, 119, 0, 120, 0, 0, 0,
0, 121, 0, 0, 143, 3, 0, 151, 152, 153,
0, 13, 14, 0, 0, 41, 0, 0, 0, 54,
55, 0, 0, 62, 0, -2, 22, 64, 0, 0,
70, 74, 0, 76, 79, 0, 0, 91, 0, 0,
0, 0, 0, 0, 34, 29, 35, 30, 0, 0,
0, 0, 49, 51, 126, 125, 122, 123, 124, 126,
140, 146, 149, 141, 5, 6, 150, 0, 12, 0,
38, 44, 39, 40, 0, 0, 56, 0, 0, 57,
0, 0, 58, 0, 69, 83, 73, 75, 78, 0,
0, 77, 71, 0, 0, 0, 128, 0, 20, 24,
31, 0, 32, 0, 33, 104, 142, 0, 0, 0,
10, 11, 16, 0, -2, -2, 0, 52, 53, 0,
59, 0, 0, 0, 0, 0, 92, 93, 94, 0,
129, 131, 132, 0, 135, 0, 37, 36, 144, 145,
147, 148, 0, 0, 43, 0, 66, 0, 0, 0,
0, 82, 80, 127, 130, 134, 133, 0, 15, 17,
61, 0, 0, 68, 63, 81, 0, 65, 67, 136 };
#define YYFLAG -1000
#define YYERROR goto yyerrlab
#define YYACCEPT return(0)
#define YYABORT return(1)
/* parser for yacc output */
#ifdef YYDEBUG
int yydebug = 0; /* 1 for debugging */
#endif
YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
int yychar = -1; /* current input token number */
int yynerrs = 0; /* number of errors */
short yyerrflag = 0; /* error recovery flag */
int yyparse() {
short yys[YYMAXDEPTH];
short yyj, yym;
register YYSTYPE *yypvt;
register short yystate, *yyps, yyn;
register YYSTYPE *yypv;
register short *yyxi;
yystate = 0;
yychar = -1;
yynerrs = 0;
yyerrflag = 0;
yyps = &yys[-1];
yypv = &yyv[-1];
yystack: /* put a state and value onto the stack */
#ifdef YYDEBUG
if (yydebug)
printf("state %d, char 0%o\n", yystate, yychar);
#endif
if(++yyps>&yys[YYMAXDEPTH]) {
yyerror("yacc stack overflow");
return(1);
}
*yyps = yystate;
++yypv;
#ifdef UNION
yyunion(yypv, &yyval);
#else
*yypv = yyval;
#endif
yynewstate:
yyn = yypact[yystate];
if (yyn<=YYFLAG)
goto yydefault; /* simple state */
if (yychar<0)
if ((yychar=yylex())<0)
yychar=0;
if ((yyn+=yychar)<0 || yyn>=YYLAST)
goto yydefault;
if (yychk[yyn=yyact[yyn]]==yychar) {
/* valid shift */
yychar = -1;
#ifdef UNION
yyunion(&yyval, &yylval);
#else
yyval = yylval;
#endif
yystate = yyn;
if (yyerrflag>0)
--yyerrflag;
goto yystack;
}
yydefault:
/* default state action */
if ((yyn=yydef[yystate])== -2) {
if (yychar<0)
if ((yychar=yylex())<0)
yychar = 0;
/* look through exception table */
for (yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2)
; /* VOID */
for (yyxi+=2; *yyxi >= 0; yyxi+=2) {
if (*yyxi==yychar)
break;
}
if ((yyn=yyxi[1])<0)
return(0); /* accept */
}
if (yyn==0) {
/* error */
/* error ... attempt to resume parsing */
switch (yyerrflag) {
case 0: /* brand new error */
yyerror( "syntax error" );
yyerrlab: ++yynerrs;
case 1:
case 2: /* incompletely recovered error ... try again */
yyerrflag = 3;
/* find a state where "error" is a legal shift action */
while (yyps>=yys) {
yyn = yypact[*yyps] + YYERRCODE;
if (yyn>=0 && yyn<YYLAST
&& yychk[yyact[yyn]]==YYERRCODE) {
yystate = yyact[yyn];
/* simulate a shift of "error" */
goto yystack;
}
yyn = yypact[*yyps];
/* the current yyps has no shift on "error",
pop stack */
#ifdef YYDEBUG
if (yydebug)
printf("error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1]);
#endif
--yyps;
--yypv;
}
/* there is no state on the stack with an error shift
... abort */
yyabort: return(1);
case 3: /* no shift yet; clobber input char */
#ifdef YYDEBUG
if (yydebug)
printf("error recovery discards char %d\n", yychar);
#endif
if (yychar==0)
goto yyabort; /* don't discard EOF, quit */
yychar = -1;
goto yynewstate; /* try again in the same state */
}
}
/* reduction by production yyn */
#ifdef YYDEBUG
if (yydebug)
printf("reduce %d\n",yyn);
#endif
yyps -= yyr2[yyn];
yypvt = yypv;
yypv -= yyr2[yyn];
#ifdef UNION
yyunion(&yyval, &yypv[1]);
#else
yyval = yypv[1];
#endif
yym=yyn;
/* consult goto table to find next state */
yyn = yyr1[yyn];
yyj = yypgo[yyn] + *yyps + 1;
if (yyj>=YYLAST || yychk[yystate=yyact[yyj]]!= -yyn)
yystate = yyact[yypgo[yyn]];
switch(yym) {
case 1:
# line 72
{inputExpr = yypvt[-0]; sp-=1;} break;
case 2:
# line 73
{inputExpr = letrec(yypvt[-0],yypvt[-1]); sp-=2;} break;
case 3:
# line 74
{valDefns = yypvt[-1]; sp-=3;} break;
case 4:
# line 75
{syntaxError("input");} break;
case 5:
# line 77
{yyval = gc2(yypvt[-2]);} break;
case 6:
# line 78
{yyval = gc3(cons(yypvt[-0],yypvt[-2]));} break;
case 7:
# line 79
{yyval = gc0(NIL);} break;
case 8:
# line 80
{yyval = gc1(cons(yypvt[-0],NIL));} break;
case 9:
# line 81
{syntaxError("definition");} break;
case 10:
# line 86
{typeDefn(yypvt[-1],yypvt[-2],yypvt[-0]); sp-=4;} break;
case 11:
# line 87
{dataDefn(yypvt[-1],yypvt[-2],rev(yypvt[-0])); sp-=4;} break;
case 12:
# line 89
{yyval = gc2(ap(yypvt[-1],yypvt[-0]));} break;
case 13:
# line 90
{yyval = yypvt[-0];} break;
case 14:
# line 91
{syntaxError("type defn lhs");} break;
case 15:
# line 93
{yyval = gc3(cons(yypvt[-0],yypvt[-2]));} break;
case 16:
# line 94
{yyval = gc1(cons(yypvt[-0],NIL));} break;
case 17:
# line 96
{yyval = gc3(ap(ap(yypvt[-1],yypvt[-2]),yypvt[-0]));} break;
case 18:
# line 97
{yyval = yypvt[-0];} break;
case 19:
# line 98
{yyval = yypvt[-0];} break;
case 20:
# line 109
{yyval = gc3(ap(QUAL,pair(yypvt[-2],yypvt[-0])));} break;
case 21:
# line 110
{yyval = yypvt[-0];} break;
case 22:
# line 112
{yyval = gc1(checkContext(yypvt[-0]));} break;
case 23:
# line 114
{yyval = yypvt[-0];} break;
case 24:
# line 115
{yyval = gc3(ap(ap(ARROW,yypvt[-2]),yypvt[-0]));} break;
case 25:
# line 116
{syntaxError("type expression");} break;
case 26:
# line 118
{yyval = yypvt[-0];} break;
case 27:
# line 119
{yyval = yypvt[-0];} break;
case 28:
# line 121
{yyval = yypvt[-0];} break;
case 29:
# line 122
{yyval = yypvt[-0];} break;
case 30:
# line 123
{yyval = gc2(UNIT);} break;
case 31:
# line 124
{yyval = gc3(yypvt[-1]);} break;
case 32:
# line 125
{yyval = gc3(buildTuple(yypvt[-1]));} break;
case 33:
# line 126
{yyval = gc3(ap(LIST,yypvt[-1]));} break;
case 34:
# line 128
{yyval = gc2(ap(yypvt[-1],yypvt[-0]));} break;
case 35:
# line 129
{yyval = gc2(ap(yypvt[-1],yypvt[-0]));} break;
case 36:
# line 131
{yyval = gc3(cons(yypvt[-0],yypvt[-2]));} break;
case 37:
# line 132
{yyval = gc3(cons(yypvt[-0],cons(yypvt[-2],NIL)));} break;
case 38:
# line 137
{fixDefn(LEFT_ASS,yypvt[-2],yypvt[-1],yypvt[-0]); sp-=3;} break;
case 39:
# line 138
{fixDefn(RIGHT_ASS,yypvt[-2],yypvt[-1],yypvt[-0]);sp-=3;} break;
case 40:
# line 139
{fixDefn(NON_ASS,yypvt[-2],yypvt[-1],yypvt[-0]); sp-=3;} break;
case 41:
# line 141
{yyval = gc1(checkPrec(yypvt[-0]));} break;
case 42:
# line 142
{yyval = gc0(mkInt(DEF_PREC));} break;
case 43:
# line 144
{yyval = gc3(cons(yypvt[-0],yypvt[-2]));} break;
case 44:
# line 145
{yyval = gc1(cons(yypvt[-0],NIL));} break;
case 45:
# line 147
{yyval = yypvt[-0];} break;
case 46:
# line 148
{yyval = yypvt[-0];} break;
case 47:
# line 149
{yyval = gc1(varMinus);} break;
case 48:
# line 151
{yyval = yypvt[-0];} break;
case 49:
# line 152
{yyval = gc3(yypvt[-1]);} break;
case 50:
# line 154
{yyval = yypvt[-0];} break;
case 51:
# line 155
{yyval = gc3(yypvt[-1]);} break;
case 52:
# line 160
{primDefn(intOf(yypvt[-3]),yypvt[-2],yypvt[-0]); sp-=4;} break;
case 53:
# line 162
{yyval = gc3(cons(yypvt[-0],yypvt[-2]));} break;
case 54:
# line 163
{yyval = gc1(cons(yypvt[-0],NIL));} break;
case 55:
# line 164
{syntaxError("primitive defn");} break;
case 56:
# line 166
{yyval = gc2(pair(yypvt[-1],yypvt[-0]));} break;
case 57:
# line 171
{classDefn(intOf(yypvt[-2]),yypvt[-1],yypvt[-0]); sp-=3;} break;
case 58:
# line 172
{instDefn(intOf(yypvt[-2]),yypvt[-1],yypvt[-0]); sp-=3;} break;
case 59:
# line 174
{yyval = gc3(pair(yypvt[-2],yypvt[-0]));} break;
case 60:
# line 175
{yyval = gc1(pair(NIL,yypvt[-0]));} break;
case 61:
# line 177
{yyval = gc4(yypvt[-1]);} break;
case 62:
# line 178
{yyval = gc0(NIL);} break;
case 63:
# line 180
{yyval = gc4(yypvt[-1]);} break;
case 64:
# line 181
{yyval = gc0(NIL);} break;
case 65:
# line 183
{yyval = gc3(cons(yypvt[-0],yypvt[-2]));} break;
case 66:
# line 184
{yyval = gc1(cons(yypvt[-0],NIL));} break;
case 67:
# line 186
{yyval = gc3(sigdecl(yypvt[-1],yypvt[-2],yypvt[-0]));} break;
case 68:
# line 187
{yyval = gc2(pair(yypvt[-1],yypvt[-0]));} break;
case 69:
# line 192
{yyval = gc3(sigdecl(yypvt[-1],yypvt[-2],yypvt[-0]));} break;
case 70:
# line 193
{yyval = gc2(pair(yypvt[-1],yypvt[-0]));} break;
case 71:
# line 195
{yyval = gc3(cons(yypvt[-0],yypvt[-2]));} break;
case 72:
# line 196
{yyval = gc1(cons(yypvt[-0],NIL));} break;
case 73:
# line 198
{yyval = gc2(letrec(yypvt[-0],yypvt[-1]));} break;
case 74:
# line 199
{yyval = yypvt[-0];} break;
case 75:
# line 201
{yyval = gc2(pair(yypvt[-1],yypvt[-0]));} break;
case 76:
# line 202
{yyval = gc1(grded(rev(yypvt[-0])));} break;
case 77:
# line 204
{yyval = gc4(yypvt[-1]);} break;
case 78:
# line 206
{yyval = gc2(cons(yypvt[-0],yypvt[-1]));} break;
case 79:
# line 207
{yyval = gc1(cons(yypvt[-0],NIL));} break;
case 80:
# line 209
{yyval = gc4(pair(yypvt[-1],pair(yypvt[-2],yypvt[-0])));} break;
case 81:
# line 216
{yyval = gc5(pair(yypvt[-4],pair(yypvt[-0],yypvt[-3])));} break;
case 82:
# line 217
{yyval = gc4(pair(yypvt[-3],pair(yypvt[-0],yypvt[-2])));} break;
case 83:
# line 219
{yyval = gc3(cons(yypvt[-0],yypvt[-2]));} break;
case 84:
# line 220
{yyval = gc1(cons(yypvt[-0],NIL));} break;
case 85:
# line 222
{yyval = yypvt[-0];} break;
case 86:
# line 223
{yyval = gc3(varMinus);} break;
case 87:
# line 225
{yyval = yypvt[-0];} break;
case 88:
# line 226
{yyval = gc3(yypvt[-1]);} break;
case 89:
# line 228
{yyval = yypvt[-0];} break;
case 90:
# line 229
{yyval = gc3(yypvt[-1]);} break;
case 91:
# line 234
{yyval = gc4(ap(LAMBDA,
pair(rev(yypvt[-2]),
pair(yypvt[-1],yypvt[-0]))));} break;
case 92:
# line 237
{yyval = gc6(letrec(yypvt[-3],yypvt[-0]));} break;
case 93:
# line 238
{yyval = gc6(ap(COND,triple(yypvt[-4],yypvt[-2],yypvt[-0])));} break;
case 94:
# line 239
{yyval = gc6(ap(CASE,pair(yypvt[-4],rev(yypvt[-1]))));} break;
case 95:
# line 240
{yyval = gc3(ap(ESIGN,pair(yypvt[-2],yypvt[-0])));} break;
case 96:
# line 241
{yyval = yypvt[-0];} break;
case 97:
# line 242
{syntaxError("expression");} break;
case 98:
# line 244
{yyval = gc2(cons(yypvt[-0],yypvt[-1]));} break;
case 99:
# line 245
{yyval = gc1(cons(yypvt[-0],NIL));} break;
case 100:
# line 247
{yyval = yypvt[-0];} break;
case 101:
# line 248
{yyval = gc3(ap(ap(yypvt[-1],yypvt[-2]),yypvt[-0]));} break;
case 102:
# line 249
{yyval = gc1(tidyInfix(yypvt[-0]));} break;
case 103:
# line 251
{yyval = gc3(ap(ap(yypvt[-1],yypvt[-2]),yypvt[-0]));} break;
case 104:
# line 252
{yyval = gc5(ap(ap(yypvt[-1],
ap(ap(yypvt[-3],singleton(yypvt[-4])),
yypvt[-2])),yypvt[-0]));} break;
case 105:
# line 256
{if (isInt(yypvt[-0]))
yyval = gc2(mkInt(-intOf(yypvt[-0])));
else
yyval = gc2(ap(varNegate,yypvt[-0]));
} break;
case 106:
# line 261
{yyval = yypvt[-0];} break;
case 107:
# line 263
{yyval = gc2(ap(yypvt[-1],yypvt[-0]));} break;
case 108:
# line 264
{yyval = yypvt[-0];} break;
case 109:
# line 266
{yyval = yypvt[-0];} break;
case 110:
# line 267
{yyval = gc3(ap(ASPAT,pair(yypvt[-2],yypvt[-0])));} break;
case 111:
# line 268
{yyval = gc2(ap(LAZYPAT,yypvt[-0]));} break;
case 112:
# line 269
{yyval = gc1(WILDCARD);} break;
case 113:
# line 270
{yyval = yypvt[-0];} break;
case 114:
# line 271
{yyval = gc2(UNIT);} break;
case 115:
# line 272
{yyval = yypvt[-0];} break;
case 116:
# line 273
{yyval = yypvt[-0];} break;
case 117:
# line 274
{yyval = yypvt[-0];} break;
case 118:
# line 275
{yyval = yypvt[-0];} break;
case 119:
# line 276
{yyval = gc3(yypvt[-1]);} break;
case 120:
# line 277
{yyval = gc3(buildTuple(yypvt[-1]));} break;
case 121:
# line 278
{yyval = gc3(yypvt[-1]);} break;
case 122:
# line 279
{yyval = gc4(ap(yypvt[-1],yypvt[-2]));} break;
case 123:
# line 280
{yyval = gc4(ap(ap(varFlip,yypvt[-2]),yypvt[-1]));} break;
case 124:
# line 281
{yyval = gc4(ap(ap(varFlip,yypvt[-2]),yypvt[-1]));} break;
case 125:
# line 283
{yyval = gc3(cons(yypvt[-0],yypvt[-2]));} break;
case 126:
# line 284
{yyval = gc3(cons(yypvt[-0],cons(yypvt[-2],NIL)));} break;
case 127:
# line 286
{yyval = gc3(cons(yypvt[-0],yypvt[-2]));} break;
case 128:
# line 287
{yyval = gc1(cons(yypvt[-0],NIL));} break;
case 129:
# line 289
{yyval = gc2(pair(yypvt[-1],yypvt[-0]));} break;
case 130:
# line 291
{yyval = gc2(letrec(yypvt[-0],yypvt[-1]));} break;
case 131:
# line 292
{yyval = yypvt[-0];} break;
case 132:
# line 294
{yyval = gc1(grded(rev(yypvt[-0])));} break;
case 133:
# line 295
{yyval = gc2(pair(yypvt[-1],yypvt[-0]));} break;
case 134:
# line 297
{yyval = gc2(cons(yypvt[-0],yypvt[-1]));} break;
case 135:
# line 298
{yyval = gc1(cons(yypvt[-0],NIL));} break;
case 136:
# line 300
{yyval = gc4(pair(yypvt[-1],pair(yypvt[-2],yypvt[-0])));} break;
case 137:
# line 305
{yyval = gc0(nameNil);} break;
case 138:
# line 306
{yyval = gc1(ap(FINLIST,cons(yypvt[-0],NIL)));} break;
case 139:
# line 307
{yyval = gc1(ap(FINLIST,rev(yypvt[-0])));} break;
case 140:
# line 308
{yyval = gc3(ap(LISTCOMP,
pair(yypvt[-2],rev(yypvt[-0]))));} break;
case 141:
# line 310
{yyval = gc3(ap(ap(varFromTo,yypvt[-2]),yypvt[-0]));} break;
case 142:
# line 311
{yyval = gc4(ap(ap(varFromThen,yypvt[-3]),yypvt[-1]));} break;
case 143:
# line 312
{yyval = gc2(ap(varFrom,yypvt[-1]));} break;
case 144:
# line 313
{yyval = gc5(ap(ap(ap(varFromThenTo,
yypvt[-4]),yypvt[-2]),yypvt[-0]));} break;
case 145:
# line 316
{yyval = gc3(cons(yypvt[-0],yypvt[-2]));} break;
case 146:
# line 317
{yyval = gc1(cons(yypvt[-0],NIL));} break;
case 147:
# line 319
{yyval = gc3(ap(FROMQUAL,pair(yypvt[-2],yypvt[-0])));} break;
case 148:
# line 320
{yyval = gc3(ap(QWHERE,pair(yypvt[-2],yypvt[-0])));} break;
case 149:
# line 321
{yyval = gc1(ap(BOOLQUAL,yypvt[-0]));} break;
case 150:
# line 327
{yyval = gc2(yypvt[-0]);} break;
case 151:
# line 328
{yyval = yypvt[-0];} break;
case 152:
# line 330
{yyval = yypvt[-0];} break;
case 153:
# line 331
{yyerrok;
if (canUnOffside()) {
unOffside();
/* insert extra token on stack*/
push(NIL);
pushed(0) = pushed(1);
pushed(1) = mkInt(row);
}
else
syntaxError("definition");
} break;/* End of actions */
}
goto yystack; /* stack new state and value */
}